<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Project;
use App\Models\ProjectCost;
use App\Models\ProjectPresent;
use App\Services\ProjectService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ProjectCostController extends Controller
{
    protected $ProjectService;
    public function __construct(ProjectService $ProjectService)
    {
        $this->ProjectService = $ProjectService;
    }

    public function index(Request $Request) {
        if(!$Request->type){
            return response()->json(['code' => '403', 'msg' => '参数错误']);
        }
        $data = ProjectCost::where('project_id',$Request->project_id)->where('type',$Request->type)->get();
        return response()->json(['code' => '200', 'msg' => '操作成功','data'=>$data]);
    }

    public function edit(Request $Request)
    {
        if(!$Request->cost){
            return response()->json(['code' => '404', 'msg' => '请选择要操作的记录']);
        }
        
        $data = $this->ProjectService->editCost($Request->cost,$Request->project_id,Auth::user()->id);
        return response()->json(['code' => '200', 'msg' => '操作成功','data'=>$data]);
    }
}
